package com.archgeek.spark.examples.v20210223

import org.apache.spark.{SparkConf, SparkContext}

/**
 *
 *
 * Create by pizhihui on 2021-02-23
 */
object SparkBroadcast {


  def main(args: Array[String]): Unit = {

    val conf = new SparkConf().setMaster("local").setAppName("SparkBroadcastDemo")
    val sc = new SparkContext(conf)

    val data = sc.parallelize(List(
      "hello world",
      "hello spark",
      "hi kangkang",
      "hello scala",
      "hi world"
    ))

    val list = List("hello", "world")
//    val list = data.map((_,1)).reduceByKey(_+_).sortBy(_._2, false).keys.take(2)
    val blist = sc.broadcast(list)


    val res = data.filter(x => blist.value.contains(x))
    res.foreach(println)


    System.in.read()


  }

}
